package com.zhou.config;

/**
 * 功能描述
 *
 * @author: scott
 * @date: 2023年02月18日 11:44
 */

public class Result<T> {
    private String code;       //正确的请求码是0，错误是-1，成功给0给前端，跟前端约定这次数据的请求是成功还是失败

    private String msg;        //这次的请求成功或者失败，会告诉前端信息

    private T data;            //实际接口返回的数据

    public String getCode(){
        return code;
    }

    public void setCode(String code){
        this.code = code;
    }

    public String getMsg(){
        return msg;
    }

    public void setMsg(String msg){
        this.msg = msg;
    }

    public T getData(){
        return data;
    }

    public void setData(T data){
        this.data = data;
    }

    public Result(){

    }

    public Result(T data){
        this.data = data;
    }

    public static Result success(){
        Result result = new Result<>();
        result.setCode("0");
        result.setMsg("成功");
        return result;
    }

    public static <T> Result<T>success(T data){
        Result<T> result = new Result<>(data);
        result.setCode("0");
        result.setMsg("成功");
        return result;
    }

    public static Result error(String code, String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        return result;
    }
}

